# coding:utf-8
from contextlib import nullcontext
import re
import json
from PyQt6.QtCore import Qt, QEasingCurve, QUrl
from PyQt6.QtGui import QPixmap
from PyQt6.QtWidgets import QWidget, QVBoxLayout
from qfluentwidgets import (SingleDirectionScrollArea, SmoothScrollArea, ToolTipFilter, PixmapLabel,
                            ScrollArea, ImageLabel, HorizontalPipsPager, PipsScrollButtonDisplayMode, VerticalPipsPager)
from qframelesswindow.webengine import FramelessWebEngineView

from .template_info_view import BaseInfoTemplateView
from .base_gallery_view import GalleryInterface
from .common.translator import Translator
from service.stock_service import getRealTimeStock
from common.utils.JsonReplace import JsonPlaceholderReplacer


class StockRecommend(BaseInfoTemplateView):
    """ Scroll interface """

    def __init__(self,   parent=None):
        t = Translator()
        super().__init__(
            "StockRecommend",
            parent=parent
        )

        # 添加一个报表
        self.addEcahtMainView("stock_recommend")

    def doSearch(self):
        print(f"查询股票{self.searchKey}")
        self.updateEchatData()

    def getEchatData(self, jsonData: dict):
        if self.searchKey is not None and self.searchKey != "":
            print(f"校验通过{self.searchKey}")
            source_data = self.getRecommendData()
            replacer = JsonPlaceholderReplacer(jsonData)
            replacer.replace_placeholder("__STOCK_DATA__", source_data)
            print(f"最终解析对象{replacer.get_modified_json()}")
            return replacer.get_modified_json()
        else:
            return jsonData

    def getRecommendData():
        return [
            {
                "value": 99,
                "name": "半导体",
                "path": "10001",
                "children": [
                    {
                        "value": 33,
                        "name": "半导体1",
                        "path": "Accounts/Access"
                    },
                    {
                        "value": 2,
                        "name": "半导体2",
                        "path": "Accounts/Authentication"
                    },
                    {
                        "value": 80,
                        "name": "半导体3",
                        "path": "Accounts/Notification"
                    }
                ]
            },
            {
                "value": 15,
                "name": "金融证券",
                "path": "Accounts",
                "children": [
                    {
                        "value": 76,
                        "name": "国盛金控",
                        "path": "Accounts/Access"
                    },
                    {
                        "value": 92,
                        "name": "东方财富",
                        "path": "Accounts/Authentication"
                    }
                ]
            }
        ]
